{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请你输入你的支付宝数字余额:8000\n",
      "0 ('华为p30', 3800)\n",
      "1 ('运动鞋', 999)\n",
      "2 ('奶茶', 15)\n",
      "3 ('衣服', 88)\n",
      "4 ('自行车', 800)\n",
      "5 ('手表', 2000)\n",
      "6 ('python教材', 70)\n",
      "请输入商品编号:1\n",
      "你已经将商品运动鞋添加到了购物车，你的支付宝余额是7001\n",
      "0 ('华为p30', 3800)\n",
      "1 ('运动鞋', 999)\n",
      "2 ('奶茶', 15)\n",
      "3 ('衣服', 88)\n",
      "4 ('自行车', 800)\n",
      "5 ('手表', 2000)\n",
      "6 ('python教材', 70)\n",
      "请输入商品编号:2\n",
      "你已经将商品奶茶添加到了购物车，你的支付宝余额是6986\n",
      "0 ('华为p30', 3800)\n",
      "1 ('运动鞋', 999)\n",
      "2 ('奶茶', 15)\n",
      "3 ('衣服', 88)\n",
      "4 ('自行车', 800)\n",
      "5 ('手表', 2000)\n",
      "6 ('python教材', 70)\n",
      "请输入商品编号:3\n",
      "你已经将商品衣服添加到了购物车，你的支付宝余额是6898\n",
      "0 ('华为p30', 3800)\n",
      "1 ('运动鞋', 999)\n",
      "2 ('奶茶', 15)\n",
      "3 ('衣服', 88)\n",
      "4 ('自行车', 800)\n",
      "5 ('手表', 2000)\n",
      "6 ('python教材', 70)\n",
      "请输入商品编号:q\n",
      "-----购物车清单-----\n",
      "('运动鞋', 999)\n",
      "('奶茶', 15)\n",
      "('衣服', 88)\n",
      "你的支付宝余额是6898\n"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "    (\"华为p30\",3800),\n",
    "    (\"运动鞋\",999),\n",
    "    (\"奶茶\",15),\n",
    "    (\"衣服\",88),\n",
    "    (\"自行车\",800),\n",
    "    (\"手表\",2000),\n",
    "    (\"python教材\",70)\n",
    "]\n",
    "\n",
    "shopping_car = []\n",
    "zhifubao = input(\"请你输入你的支付宝数字余额:\")\n",
    "if zhifubao.isdigit():\n",
    "    zhifubao = int(zhifubao)\n",
    "    while True:\n",
    "        for item in product_list:\n",
    "            print(product_list.index(item),item)\n",
    "        choice = input(\"请输入商品编号:\")\n",
    "        if choice.isdigit():\n",
    "            choice = int(choice)\n",
    "            if choice >=0 and choice <=7:\n",
    "                if zhifubao >= product_list[choice][1]:\n",
    "                    zhifubao = zhifubao - product_list[choice][1]\n",
    "                    shopping_car.append(product_list[choice])\n",
    "                    print(\"你已经将商品%s添加到了购物车，你的支付宝余额是%s\"%(product_list[choice][0],zhifubao))\n",
    "                else:\n",
    "                    print(\"你的支付宝余额不足，请选择其他商品\")\n",
    "            else:\n",
    "                print(\"你选择的商品不在商品列表里面\")\n",
    "        elif choice == \"q\":\n",
    "            print(\"-----购物车清单-----\")\n",
    "            for item in shopping_car:\n",
    "                print(item)\n",
    "            print(\"你的支付宝余额是%s\"% zhifubao)\n",
    "            break\n",
    "        else:\n",
    "            print(\"请你输入商品编码\")\n",
    "else:\n",
    "    print(\"请输入数字的支付宝余额\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
